package examples;

import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;

import java.io.*;
import java.net.Socket;

public class TcpClientDemo01 {
    public static void main(String[] args) {
        try {

            // 1.创建socket，并指定ip和端口
            Socket socket = new Socket("127.0.0.1", 6666);

            // 2.准备资源流
            BufferedReader bufferedReader = new BufferedReader(new FileReader(".\\src\\jdbc.properties"));
            PrintWriter out = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()), true);
            BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

            // 用时间戳作为结束标记
            long time = System.currentTimeMillis();
            DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());
            dataOutputStream.writeLong(time);

            // 3.获取文件内容，并发送给服务端
            String line = null;
            while ((line = bufferedReader.readLine()) != null) {
                out.println(line);
            }

            //out.println("over"); // 结束标记
            out.println(time);

            // 4.获取文件上传的结果
            String result = in.readLine();
            System.out.println(result);

            // 5.关闭资源
            bufferedReader.close();
            socket.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
